package com.walterweimod.auxiliary_attributes.event;

import com.walterweimod.auxiliary_attributes.attribute.ModAttributes;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.*;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;

import static com.walterweimod.auxiliary_attributes.util.ModAttributeUtils.*;

public class TestEvent2 {
    private static final Logger log = LoggerFactory.getLogger(TestEvent2.class);

    public static void test(){
        MobEffect regeneration = MobEffects.REGENERATION;
        LivingEntity livingEntity = null;
        livingEntity.heal(3.0f);
        livingEntity.setAbsorptionAmount(4.6f);
    }

    @SubscribeEvent
    public static void test2(LivingHurtEvent event){
        LivingEntity livingEntity = event.getEntityLiving();
        AttributeMap attributeMap = livingEntity.getAttributes();
        AttributeInstance defense = attributeMap.getInstance(ModAttributes.DEFENSE.get());
        removeAttributeModifier(
                livingEntity,
                defense.getAttribute(),
                UUID.randomUUID()
        );
        addAttributeModifier(
                livingEntity,
                defense.getAttribute(),
                12.0D,
                UUID.randomUUID(),
                AttributeModifier.Operation.ADDITION,
                false
        );

        AtomicReference<Float> a = new AtomicReference<>((float) 0);

        livingEntity.hurt(event.getSource(), 83);

        new DamageSource("as").isBypassMagic();
    }
}
